#include <iostream>
using namespace std;

class Element;

class Visitor{
  public:
    Visitor(){};
    virtual ~Visitor(){};
    virtual void visitElementA(Element* a){};
    virtual void visitElementB(Element* b){};
};

class Element {
  public:
    Element(){};
    virtual ~Element(){};
    virtual void Accept(Visitor* v){};
};

class ConcreteVistor : public Visitor {
  public:
    void visitElementA(Element* a) {
      cout << " Visitor will visit Element a ..." << endl;
    }
    void visitElementB(Element* b) {
      cout << " Visitor will visit Element b ..." << endl;
    }
};

class ConcreteElementA :public Element {
public:
	ConcreteElementA(){};
  void Accept(Visitor* v){
		cout << "ConcreteElementA : " << endl;
		v->visitElementB(this);				// 访问具体对象	即自身
	}
};

class ConcreteElementB :public Element {
public:
	ConcreteElementB(){};
  void Accept(Visitor* v){
		cout << "ConcreteElementB : " << endl;
		v->visitElementB(this);				// 访问具体对象	即自身
	}
};


int main() {
    Visitor *vis = new ConcreteVistor();
    Element *elm = new ConcreteElementA();
    elm->Accept(vis);

    delete elm;
    delete vis;

    return 0;
}

